home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / OCT16IN < prev    next >
Encoding:
Text File  |  1985-12-22  |  1.5 KB  |  50 lines

  1. ;-------------------------oct16in routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 45
  4. ;
  5. ; NAME OCT16IN
  6. ; ROUTINE FOR conversion from ASCII octal to 16-bit Binary
  7. ;
  8. ; FUNCTION: This routine accepts an octal number from the standard input
  9. ; device and converts it to internal 16-bit binary form.
  10. ; INPUT: The individual digits of the octal number are received in ASCII
  11. ; through a call to a standard I/O routine.  The valid digits are 0 - 7.
  12. ; An ASCII code other than for a valid digit will terminate the routine.
  13. ;
  14. ; OUTPUT: A 16-bit binary number is returned in the DX register.
  15. ; REGISTERS USED:  Only DX is modified. It returns the result.
  16. ; SEGMENTS REFERENCED:  None
  17. ; ROUTINES CALLED:  STDIN
  18. ; SPECIAL NOTES: None
  19. ;
  20. ; ROUTINE TO CONVERT FROM ASCII OCTAL TO INTERNAL 16-BIT BINARY
  21. ;
  22. oct16in    proc    far
  23. ;
  24.     push    cx        ; save registers
  25.     push    ax
  26. ;
  27.     mov    dx,0        ; initialize DX
  28. ;
  29. oct16in1:
  30.     call    stdin        ; a digit comes in in AL
  31.     sub    al,30h        ; reduce from ASCII
  32.     jl    oct16in2    ; check if too low
  33.     cmp    al,7
  34.     jg    oct16in2    ; check if too high
  35.     cbw            ; convert to word
  36. ;
  37.     mov    cl,3
  38.     sal    dx,cl        ; shift dx left once
  39.     add    dx,ax        ; add in digit
  40.     jmp     oct16in1
  41. ;
  42. oct16in2:
  43. ;
  44.     pop    ax        ; restore registers
  45.     pop    cx
  46.     ret            ; return
  47. ;
  48. oct16in    endp
  49. ;-------------------------oct16in routine ends---------------------------+
  50.